<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
    <!-- 生产环境中不建议使用 jsx babel转译库 将jsx转化为原生js -->
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
</head>
<body>
    <div id="example"></div>
        <script type="text/babel">
            // 数组元素中使用的 key 在其兄弟之间应该是独一无二的。然而，它们不需要是全局唯一的。当我们生成两个不同的数组时，我们可以使用相同的键。
            function Blog(props){
                const sidebar=(
                    <ul>
                        {
                            props.posts.map((post)=>
                                <li key={post.id}>
                                    {post.title}    
                                </li>
                            )
                        }    
                    </ul>
                );
                const content=props.posts.map((post)=>
                    <div key={post.id}>
                        <h3>{post.title}</h3>
                        <p>{post.content}</p>    
                    </div>
                )
                return (
                    <div>
                        {sidebar}
                        <hr/>
                        {content}
                    </div>
                )
            }

            const posts = [
                {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
                {id: 2, title: 'Installation', content: 'You can install React from npm.'}
            ];
            ReactDOM.render(
                <Blog posts={posts} />,
                document.getElementById('example')
            )
        </script>
</body>
</html>